"use strict"

var Koa = require('koa')
var sha1 = require('sha1')
var config = {
    wechat: {
<<<<<<< HEAD
        appID: 'wxd88a42cf8d2f2e6b',
        appSecret: 'e3d837cbb426851260f6623a0d266c2a',
        token: 'wechatyoulishuvuecharts'
=======
        appID: 'wxe4bb339acb4c4ab8',
        appSecret: 'ef834df48d6b0754c16a3fd1a2ece0e4',
        token: 'vuecharts'
>>>>>>> cb2114b3a2bdfef7b08fd1b835cc82711d54c501
    }
}

var app = new Koa()

app.use(function*(next) {
    console.log(this.query)

<<<<<<< HEAD
     //验证逻辑
    var token = config.wechat.token
    var signature = this.query.signature
    var nonce = this.query.nonce
    var timestamp = this.query.timestamp
    var echostr = this.query.echostr
     //字段排序
    var str = [token, timestamp, nonce].sort().join('')
     //加密
    var sha = sha1(str)
=======
    // 验证逻辑
    // var token = config.wechat.token
    // var signature = this.query.signature
    // var nonce = this.query.nonce
    // var timestamp = this.query.timestamp
    // var ecostr = this.query.ecostr
    //     //字段排序
    // var str = [token, timestamp, nonce].sort().join('')
    //     //加密
    // var sha = sha1(str)
>>>>>>> cb2114b3a2bdfef7b08fd1b835cc82711d54c501

     if (sha === signature) {
         this.body = echostr + ''
     } else {
        //否则说明这个请求不是从微信中提交过来的
         this.body = 'wrong'
     }
})

app.listen(80)
<<<<<<< HEAD
console.log("listening : 80 端口")
=======
console.log("listening : 80")
>>>>>>> cb2114b3a2bdfef7b08fd1b835cc82711d54c501
